package de.tum.in.eist.poll.client.widgets.content;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.rpc.AsyncCallback;
import de.tum.in.eist.poll.client.PollService;
import de.tum.in.eist.poll.client.PollServiceAsync;
import de.tum.in.eist.poll.shared.Lecture;

/**
 * factory that creates the feedback form for a given lecture
 * 
 * @author aperture
 */

public class FeedbackUIFactory implements ContentFactory {
	private final PollServiceAsync pollService = GWT.create(PollService.class);
	private Lecture selectedLecture;
	boolean rated = false;

	public FeedbackUIFactory(final Lecture selectedLecture) {
		this.selectedLecture = selectedLecture;
		pollService.checkRatingStatus(selectedLecture,
				new AsyncCallback<Boolean>() {

					@Override
					public void onSuccess(final Boolean result) {
						Scheduler.get().scheduleEntry(new Command() {

							@Override
							public void execute() {
								rated = result;
							}
						});
					}

					@Override
					public void onFailure(Throwable caught) {
						// TODO Auto-generated method stub

					}
				});
	}

	@Override
	public Content createContent(String parameter) {
		return null;
	}

	/**
	 * creates the actual form
	 * 
	 * @param selectedLecture
	 *            the Lecture object that should be used
	 * @return
	 */
	public Content createContent() {
//		
//		if (rated == true) {
//			return new FeedbackUI();
//		} else {
			return new FeedbackUI(this.selectedLecture);
//		}
	}

}
